<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新品有戏后台管理</title>
    <link href="__CSS__/boot.css" rel="stylesheet">
    <link href="__STATIC__/layui/css/layui.css" rel="stylesheet">
    <script src="__JS__/jquery.js"></script>
    <script src="__JS__/layer/layer.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <style>
        tr td{
            text-align: center;
            vertical-align: middle!important;
        }
    </style>
</head>
<body>
<div style="height: 10px;"></div>
<div style="width: 700px;">
<form action=""  id="update" onsubmit="return false">
    <input type="hidden" name="id" value="{$result['id']}">
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 100px">商品名称</label>
        <div class="layui-input-block">
            <input type="text" name="pname" required  value="{$result['pname']}" readonly lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 100px">单价(元)</label>
        <div class="layui-input-block">
            <input type="text" name="price" readonly  value="{$result['price']}" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 110px">购买数量(个)</label>
        <div class="layui-input-block">
            <input type="text" name="number" readonly  value="{$result['number']}" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 100px">邮寄人</label>
        <div class="layui-input-block">
            <input type="text" name="linkman" value="{$result['linkman']}" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 100px">联系电话</label>
        <div class="layui-input-block">
            <input type="text" name="telephone" value="{$result['telephone']}" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 100px">邮寄地址</label>
        <div class="layui-input-block" id="did">

        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label" style="width: 100px">详细地址</label>
        <div class="layui-input-block">
            <textarea name="address" placeholder="请输入内容" class="layui-textarea">{$result['address']}</textarea>
        </div>
    </div>
    <div class="layui-form-item" style="width: 300px;margin: 0 auto">
        <div class="layui-input-block">
            <button class="layui-btn" onclick="update()">立即修改</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</div>
</body>
<script>
    //默认1级
    $(function(){
        load(0);

    });
    //城市级联
    function load(id){
        $.ajax({
            url:"{:url('online/common/find')}",
            data:"id="+id,
            type:"get",
            dataType:"json",
            success:function(data){
                if(data == null || data.length == 0){
                    return ;
                }
                var info = "<select style='height: 30px' name='province[]'><option value=''>-请选择-</option>";
                for(var i=0;i<data.length;i++){
                    info+='<option value=\"'+data[i].id+'\">';
                    info+=data[i].name;
                    info+='</option>';
                }
                info += "</select>";
                $(info).appendTo("#did").change(function(){
                    $(this).nextAll("select").remove();
                    if($(this).val() != ""){
                        load($(this).val());
                    }
                });
            }
        });
    };
    //更新
    function update() {
        if(!$("input[name=linkman]").val()){
            layer.alert('请填写邮寄人');
            return ;
        }else if(!$("input[name=telephone]").val()){
            layer.alert('请填写联系电话');
            return;
        }else if(!$("input[name=address]").val()){
            layer.alert('请填写邮寄地址');
        }
        $.ajax({
            url:"{:url('online/mail/update')}",
            data:$("#update").serialize(),
            type:"post",
            dataType:"json",
            success:function (res) {
                if(res.success){
                    layer.alert(res.success,{bnt:['确定','取消']},function () {
                        //获取窗口索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭弹出的子页面窗口
                        parent.layer.close(index);
                        window.parent.location.reload();
                    },function () {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        window.parent.location.reload();
                    });
                }else if(res.error){
                    layer.alert(res.error);
                }
            }
        });
    }
</script>
</html>